home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Simple Question for the GURUs....
- Date: Fri, 22 Mar 1996 13:53:57 -0500
- Organization: Datalytics, Inc
- Message-ID: <3152F745.63A@datalytics.com>
- References: <1996Mar21.093000.3545@mwk.com>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- hossain@mwk.com wrote:
- >
- > *** A stupid question for the GURUS ***
- >
- > I have a very simple problem. Should the following code work ?
- >
-
- No. The correct signature for main is:
-
- int main(int argc, char **argv, char **env);
-
- or, if you prefer:
-
- int main(int argc, char *argv[], char *env[]);
-
- You can also omit the parameters you don't want (from the
- right), so these are also permissible:
-
- int main(int argc, char **argv);
- int main(int argc);
- int main(void);
-
- In each case, however, note that the return type is int. You
- cannot return a string, though some compilers will allow you to
- declare main as returning void (they will return zero for you).
-
- > //File:myapp.c
- >
- > char *main(int argc, char *argv[])
- > {
- > char *temp = (char *)NULL;
-
- This was a useless assignment, and the cast is not necessary.
-
- >
- > temp = (char *)malloc(40 * sizeof(char) );
-
- Try this instead of using malloc:
-
- char *temp = new char[40];
-
- >
- > if ( temp ) strcpy(temp,"Hello World..!!");
- >
- > return(temp);
- > }
- >
- > My intent is to have my myapp.exe return to me a string as it should do.
-
- The only way to "return" a string is to write it to some IPC,
- like a pipe or socket, or print it to stdout. The typical way
- to do what you want is to write to stdout:
-
- #include <iostream.h> // cout
-
- int main(void)
- {
- cout << "Hello World!" << endl;
- return 0;
- }
-
- >
- > The next part of my problem is I am setting a variable say ALPHA to the string
- > coming out of this executable. I am doing this in a PERL script as follows:
- >
- > //File: myperl.cmd
- > ..............
- > ............
- > @GREETINGS = `myapp.exe`;
- > print "Greetings from the Master : @GREETINGS\n";
- > ...........
- > ..........
- >
- > I am doing this in Windows NT environment.The PERL script appear to hang at the
- > line @GREETINGS = `myapp.exe`. What is the problem.
- >
-
- With the change I gave above, your code should work fine. The
- Perl code you wrote is waiting to capture the stdout output from
- myapp.exe. Since there is none, there is nothing to capture.
-
- > I will appreciate a response from anyone, who can help solve this apparently
- > simple problem. Please e-mail me directly at "hossain@mwk.com".
- >
- > Hoping to hear from someone there.
- >
- > thanks
- > akhtar
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-